function InitSwitchObj() {
	IMGLIST = $("#IMG_UL_LIST_1");
	IMGLIST2 = $("#IMG_UL_LIST_2");
	IMGINDEX = $("#IMG_INDEX_UL_LIST_1");
	IMGINDEX2 = $("#IMG_INDEX_UL_LIST_2");
	MAXINDEX = IMGLIST.find("li").length;
	MAXINDEX2 = IMGLIST2.find("li").length;
	currIndex = 0;
	currIndex2 = 0;
	currImgIndex = IMGINDEX.find("li:eq(" + currIndex + ")");
	currImgLi = IMGLIST.find("li:eq(" + currIndex2 + ")");
	currImgIndex2 = IMGINDEX2.find("li:eq(" + currIndex + ")");
	currImgLi2 = IMGLIST2.find("li:eq(" + currIndex2 + ")");
	currImgLi.show();
	currImgLi2.show();
	interValTime = 3000;
	fadeInTime = 800;
	fadeOutTime = 1000;
	ImageAutoSwitch();
	ImageManualSwitch();
	ImageStopSwitch();
}

// 執行時間
var interValTime = 0;
// 下一張圖片顯示時間
var fadeInTime = 0;
// 上一張圖片的消失時間
var fadeOutTime = 0;
// 保存當前圖片定時的對象
var imageTimer = null;
// 當前的索引
var currIndex = null;
var currIndex2 = null;
// 當前圖片的所以
var currImgIndex = null;
var currImgIndex2 = null;
// 當前圖片
var currImgLi = null;
var currImgLi2 = null;
// 記錄需要切換的圖片集合
var IMGLIST = null;
var IMGLIST2 = null;
// 記錄需要切換的圖片集合的索引。
var IMGINDEX = null;
var IMGINDEX2 = null;
// 最大圖片個數
var MAXINDEX = null;
var MAXINDEX2 = null;
// 自動定時切換。
function ImageAutoSwitch() {
	if (imageTimer != null) {
		clearInterval(imageTimer);
	}
	imageTimer = setInterval("IntervalImage()", interValTime);
}
// 手動切換圖片
function ImageManualSwitch() {
	IMGINDEX.find("li").each(function(i) {
		$(this).hover(function() {
			if (imageTimer != null) {
				clearInterval(imageTimer);
			}
			currIndex = i;
			ImageSwitchChange();
		}, function() {
			ImageAutoSwitch();
		});
	});
	IMGINDEX2.find("li").each(function(i) {
		$(this).hover(function() {
			if (imageTimer != null) {
				clearInterval(imageTimer);
			}
			currIndex2 = i;
			ImageSwitchChange();
		}, function() {
			ImageAutoSwitch();
		});
	});
}
// 鼠標放到圖片上的換，停止切換
function ImageStopSwitch() {
	IMGLIST.find("li").each(function() {
		$(this).hover(function() {
			if (imageTimer != null) {
				clearInterval(imageTimer);
			}
		}, function() {
			ImageAutoSwitch();
		});
	});
	IMGLIST2.find("li").each(function() {
		$(this).hover(function() {
			if (imageTimer != null) {
				clearInterval(imageTimer);
			}
		}, function() {
			ImageAutoSwitch();
		});
	});
}
// 自动切换图片
function IntervalImage() {
	currIndex = parseFloat(currIndex);
	currIndex = currIndex + 1;
	currIndex2 = parseFloat(currIndex2);
	currIndex2 = currIndex2 + 1;
	// 如果切換到最大數量的時候則從頭開始
	if (currIndex >= MAXINDEX) {
		currIndex = 0;
	}
	if (currIndex2 >= MAXINDEX2) {
		currIndex2 = 0;
	}
	// 將原來的現實圖片索引的背景透明
	ImageSwitchChange();
}
// 切換圖片的時候，響應的圖片要實現漸變效果
function ImageSwitchChange() {
	if (currImgIndex != null) {
		currImgIndex.css({
			"background-color" : "transparent"
		});
	}
	currImgIndex = IMGINDEX.find("li:eq(" + currIndex + ")");
	imgLi = IMGLIST.find("li:eq(" + currIndex + ")");
	currImgIndex.css({
		"background-color" : "#999999"
	});
	if (currImgLi != null) {
		currImgLi.fadeOut(fadeOutTime, function() {
			imgLi.fadeIn(fadeInTime);
		});
	}
	currImgLi = imgLi;
	if (currImgIndex2 != null) {
		currImgIndex2.css({
			"background-color" : "transparent"
		});
	}
	currImgIndex2 = IMGINDEX2.find("li:eq(" + currIndex2 + ")");
	imgLi2 = IMGLIST2.find("li:eq(" + currIndex2 + ")");
	currImgIndex2.css({
		"background-color" : "#999999"
	});
	if (currImgLi != null) {
		currImgLi2.fadeOut(fadeOutTime, function() {
			imgLi2.fadeIn(fadeInTime);
		});
	}
	currImgLi2 = imgLi2;
}
function bulidPagnation(totalcount, limit, page, id, renderId, nowId, endId) {
	var previewPageStr = '<span class="disabled">&lt;</span>';
	var nextPageStr = '<span><a href="#?page=2">&gt;</a></span>';
	var currentPageStr = '<span class="current">1</span>';
	var showPageStr = '<a href="#?page=2">2</a>';
	var totalPages = Math.floor((totalcount + limit - 1) / limit);
	var startPage = nowId;
	var endPage = startPage + 4;
	if (page >= 4)
		if ((page - nowId) >= 3) {
			startPage = page - 2;
			endPage = startPage + 4;
		}
	if (nowId != 1)
		if ((endId - page) >= 3) {
			startPage = page - 2;
			endPage = startPage + 4;
		}
	if (endPage > totalPages) {
		endPage = totalPages;
		nextPageStr = '<span class="disabled">&gt;</span>';
	} else {
		nextPageStr = '<a href="javascript:bulidPagnation(' + totalcount + ','
				+ limit + ',' + (page + 1) + ',\'' + id + '\',\'' + renderId
				+ '\',' + startPage + ',' + endPage + ')">&gt;</a>';
	}
	if (startPage > 1) {
		previewPageStr = '<a href="javascript:bulidPagnation(' + totalcount
				+ ',' + limit + ',' + (page - 1) + ',\'' + id + '\',\''
				+ renderId + '\',' + startPage + ',' + endPage + ')">&lt</a>';
	}
	var str = previewPageStr;
	for (var i = startPage; i <= endPage; i++) {
		if (i == page)
			str += '<span class="current">' + i + '</span>';
		else
			str += '<a href="javascript:bulidPagnation(' + totalcount + ','
					+ limit + ',' + (i) + ',\'' + id + '\',\'' + renderId
					+ '\',' + startPage + ',' + endPage + ')">' + i + '</a>';
	}
	str += nextPageStr;
	$('#meidTbar').html(str);
	if (!initFlag)
		return;
	$.get('brand/findAllMessage.shtml?pageNo=' + page + '&limit=' + limit
			+ '&id=' + id, function(mes) {
		var json = eval('(' + mes + ')');
		var str = '<ul>';
		for (var i = 0; i < json[0]['list'].length; i++) {
			var tc = json[0]['list'][i]['category'];
			if(tc == null || tc == "")
				tc = "品牌介绍"
			var strTemp = '';
			var rc = json[0]['list'][i]['recommend'];
			if(rc == "1")
				strTemp = '<img src="../resource/img/index/index_recommend.jpg"/>';
			
			str += '<li><table border="0" width="100%" cellpadding="0" cellspacing="0" id="mes_title_'+json[0]['list'][i]['id']+'">' +
					'<tr><td >' +
					'<a href="javascript:onopenMessage1('
					+ json[0]['list'][i]['id'] + ')">' +
					'<span style="font-size:14px; color:#069">' +json[0]['list'][i]['titleSpe']+
					'</span></a></td></tr></table>' +
					'<div style="display: none" id="mes_content_'+json[0]['list'][i]['id']+'">' +
					'<table width="100%" cellpadding="0" cellspacing="0" border="0">' +
					'<tr><td height="50px" valign="middle" class="info_title"><a name="sign_'+json[0]['list'][i]['id']+'"></a>' +
					'【'+tc+'】&nbsp;&nbsp;' +json[0]['list'][i]['title']+'&nbsp;&nbsp;' +
					'<span id="hm_'+json[0]['list'][i]['id']+'" class="slideUp111" onclick="hideMessage1(\''+json[0]['list'][i]['id']+'\')">收起</span>&nbsp;&nbsp;' +
					strTemp +
					'</td></tr>' +
					'<tr><td align="left">' +
					'<div class="info_content" align="left"><hr/><span style="float:left">'+json[0]['list'][i]['creatTimeFormat']+'</span><br/>'+json[0]['list'][i]['content']+
					'</div></td></tr><tr><td height="20px">&nbsp;</td></tr></table></div>'+
					'</li>';
		}
		str += '</ul>';
		$('#meid').html(str);
	})
}

function bulidPagnation1(totalcount, limit, page, id, renderId, nowId, endId) {
	var previewPageStr = '<span class="disabled">&lt;</span>';
	var nextPageStr = '<span><a href="#?page=2">&gt;</a></span>';
	var currentPageStr = '<span class="current">1</span>';
	var showPageStr = '<a href="#?page=2">2</a>';
	var totalPages = Math.floor((totalcount + limit - 1) / limit);
	var startPage = nowId;
	var endPage = startPage + 4;
	if (page >= 4)
		if ((page - nowId) >= 3) {
			startPage = page - 2;
			endPage = startPage + 4;
		}
	if (nowId != 1)
		if ((endId - page) >= 3) {
			startPage = page - 2;
			endPage = startPage + 4;
		}
	if (endPage > totalPages) {
		endPage = totalPages;
		nextPageStr = '<span class="disabled">&gt;</span>';
	} else {
		nextPageStr = '<a href="javascript:bulidPagnation1(' + totalcount + ','
				+ limit + ',' + (page + 1) + ',\'' + id + '\',\'' + renderId
				+ '\',' + startPage + ',' + endPage + ')">&gt;</a>';
	}
	if (startPage > 1) {
		previewPageStr = '<a href="javascript:bulidPagnation1(' + totalcount
				+ ',' + limit + ',' + (page - 1) + ',\'' + id + '\',\''
				+ renderId + '\',' + startPage + ',' + endPage + ')">&lt</a>';
	}
	var str = previewPageStr;
	for (var i = startPage; i <= endPage; i++) {
		if (i == page)
			str += '<span class="current">' + i + '</span>';
		else
			str += '<a href="javascript:bulidPagnation1(' + totalcount + ','
					+ limit + ',' + (i) + ',\'' + id + '\',\'' + renderId
					+ '\',' + startPage + ',' + endPage + ')">' + i + '</a>';
	}
	str += nextPageStr;
	$('#meidTbar1').html(str);
	if (!initFlag)
		return;
	$.get('brand/findAllEvaluate.shtml?flag=1&pageNo=' + page + '&limit=' + limit
			+ '&id=' + id, function(mes) {
		var json = eval('(' + mes + ')');
		var str = '<ul>';
		for (var i = 0; i < json[0]['list'].length; i++) {
			var pjid = json[0]['list'][i]['id'];
			str += '<li><table width="940" border="0" cellspacing="0" cellpadding="0">' +
					'<tr><td width="65" align="center" valign="top" style="line-height:24px">' +
					'<img src="../resource/img/goodBrand/3'+json[0]['list'][i]['sex']+'.jpg" width="23" height="22" /><br />' +json[0]['list'][i]['username']+
					'性别'+json[0]['list'][i]['sex']
					'</td><td width="5">&nbsp;</td><td width="870" align="left" valign="top">' +
					'<div class="px1-4-1">'+json[0]['list'][i]['title']+'</div>'+
					'<div class="px1-4-2">'+json[0]['list'][i]['content']+'&nbsp;&nbsp;(评论时间:<s:property value="createTimeStr"/>)';
			if((json[0]['list'][i]['reply']==null||""==json[0]['list'][i]['reply'])&&loginuserId==shangjiaId){
				str += '  &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:showReplyArea(\''+pjid+'\')">商家回复</a>';
			}
			str += '</div>';
				if(json[0]['list'][i]['reply']!=null&&""!=json[0]['list'][i]['reply']){
					str+=' <div class="px1-4-3">' +
							'<table width="" border="0" cellspacing="0" cellpadding="0"><tr>' +
							' <td width="8" height="17" style="background:url(../resource/img/goodBrand/4.jpg) no-repeat">&nbsp;</td>' +
							'<td width="" style="background:url(../resource/img/goodBrand/5.jpg) repeat-x; color:#1b638d"><span>' + brandName+
							'</span>回复：'+json[0]['list'][i]['reply']+' </td>' +
							' <td width="8" height="17" style="background:url(../resource/img/goodBrand/6.jpg) no-repeat">&nbsp;</td>' +
							'</tr></table></div>';
				}else{
					str+= '' +
							'<table width="" border="0" cellspacing="0" cellpadding="0" style="display: none" id="replyArea_'+pjid+'">' +
									'<tr>' +
									'<td width="" style="background:url(../resource/img/goodBrand/5.jpg) repeat-x; color:#1b638d"><textarea id="reply_'+pjid+'" style="width: 500px;" rows="3"></textarea></td>' +
									'<td valign="bottom">&nbsp;&nbsp;<input onclick="reply(\''+pjid+'\')" value="提交回复" type="button"/>&nbsp;&nbsp;<input type="button" value="关闭" onclick="hideReplyArea(\''+pjid+'\')"/></td>' +
									'</tr></table>';
				}
				str += '</td></tr></table></li>';
		}
		str += '</ul>';
		$('#evaluateContent').html(str);
	})
}



var numInt = 0;
var bodyWidth;
$(function() {
	InitSwitchObj();
	bodyWidth = $("body").width();
	$("#grayDiv").height($("body").height())
	initFlag = true;
	setTimeout('initevaluate()',1000);
	
	var aboutUsImg = jQuery('#info_content img');
	aboutUsImg.each(function(){
	var imgObj = new Image(); 
	imgObj.src = $(this).attr('src'); 
		if(imgObj.width>680)
	 		$(this).width(680);//所有宽度-20px
	});
	
	
})

function initevaluate(){
	var heihtTemp = GetPageScroll();
	$("#evaluate").css("top",(heihtTemp +200) + 'px');
	setTimeout('initevaluate()',1000);
}

function join() {
	/*
	if(yeid == ''){
  		alert('您还未登录，请先登录!');
  		return;
  	}
  	*/
  	if(yeid != ''){
	  	if(yetype != '3'){
	  		alert('只有业主才可以参加拼购!');
	  		return;
	  	}
  	}
//	if(joinPingouFlag=='1'){
//		alert('您已参加了该拼购!');
//	  	return;
//	}
	var heihtTemp = GetPageScroll();
	$("#joinDiv").css("top", (heihtTemp + 60) + 'px').css("left",
			(bodyWidth - 1000) / 2 + "px");
	$("#grayDiv,#joinDiv").show();
}

function showEvaluate(){
	var heihtTemp = GetPageScroll();
	$("#evaluateDiv").css("top", (heihtTemp + 60) + 'px').css("left",
			(bodyWidth - 1000) / 2 + "px");
	if(yeid == ''||isPingjia==''){
  		alert('您还未登录，请先登录!');
  		return;
  	}
  	if(yetype != '3'){
  		alert('只有业主才可以进行评价!');
  		return;
  	}
  	if('true' != joinFlag){
  		alert('只有购买过此商品的业主才可以进行评价!');
  		return;
  	}
	if(isPingjia!='0'){
  		alert('您已经评价过该商品，如需要重新评价，请进入"个人管理——评价记录"进行修改!');
  		return;
  	}	
	$("#grayDiv,#evaluateDiv").show();
}
function hideEvaluate(){
	$("#grayDiv,#evaluateDiv").hide();
}

function hideJoin() {
	$("#grayDiv,#joinDiv").hide();
}
function GetPageScroll() {
	var x, y;
	if (window.pageYOffset) { // all except IE
		y = window.pageYOffset;
		x = window.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) { // IE 6
		// Strict
		y = document.documentElement.scrollTop;
		x = document.documentElement.scrollLeft;
	} else if (document.body) { // all other IE
		y = document.body.scrollTop;
		x = document.body.scrollLeft;
	}
	return y;
}
function onopenMessage(id) {
	$.get('../brand/showShopmessagerTojson.shtml?id=' + id, function(mes) {
		var json = eval('(' + mes + ')');
		var str = '';
		if (json.length > 0) {
			// str+='<div class="luntan1">'+json[0]['titleSpe']+'</div>';
			str += '<table width="98%" style="margin-top:5px;" border="0" cellspacing="0" cellpadding="0"><tr><td align="left">';
			str += '<div style="height:433px; overflow: auto;" >';
			str += '' + json[0]['content'] + '</div></td></tr></table>';
		}
		$('#titleId').html(json[0]['titleSpe']);
		$('#viewmessage').html(str);
		viewContent();
	})
}


var messId = 0;
var url = window.location.href;
function onopenMessage1(id) {
	if(messId != 0){
		$('#mes_content_'+messId).hide();
		$('#mes_title_'+messId).show();
	}
	$('#mes_content_'+id).show();
	$('#mes_title_'+id).hide();
	messId = id;
	try{
		url = url.substring(0,url.indexOf("#"));
		window.location.href = url+"#sign_"+id;
	}catch(e){}
}

function hideMessage1(id) {
	$('#mes_content_'+id).hide();
	$('#mes_title_'+id).show();
}


function viewContent() {
	var heihtTemp = GetPageScroll();
	$("#joinDivM").css("top", (heihtTemp + 60) + 'px').css("left",
			(bodyWidth - 1000) / 2 + "px");
	$("#grayDiv,#joinDivM").show();
}

function hideViewContent() {
	$("#grayDiv,#joinDivM").hide();
}

function add() {
	/*if(yeid == ''){
  		alert('您还未登录，请先登录!');
  		return;
  	}*/
  	if(yeid != ''){
	  	if(yetype != '3'){
	  		alert('只有业主才可以参加拼购!');
	  		return;
	  	}
  	}
	var username = $("#username").val();
	if ("" == username) {
		alert("请填写真实姓名");
		$("#username").focus();
		return;
	}
	var phone = $("#phone").val();
	if ("" == phone) {
		alert("请填写手机");
		$("#phone").focus();
		return;
	}
	var address = $("#address").val();
	if ("" == address) {
		alert("请填写小区名称");
		$("#address").focus();
		return;
	}
	var parttime = $("#parttime").val();
	if ("" == parttime) {
		alert("请选择参加拼购时间");
		$("#parttime").focus();
		return;
	}

	var num = $("#num").val();
	if ("" == num) {
		alert("请填写购买数量");
		$("#num").focus();
		return;
	}
	document.getElementById('cjpgbtn').click();
	tipFlag = true;
	alert("发布成功，请等待审核");
	hideJoin();
}
var tipFlag = false;
function addResult1(mes) {
	if (!tipFlag) {
		if (mes == "1") {
			//alert("申请参加拼购成功");
		} else {
			alert("申请参加拼购失败");
		}
	}
	tipFlag = false;
}

function pingjia(){
	if(yeid == ''||isPingjia==''){
  		alert('您还未登录，请先登录!');
  		return;
  	}
  	if(yetype != '3'){
  		alert('只有业主才可以进行评价!');
  		return;
  	}
  	if('true' != joinFlag){
  		alert('只有购买过此商品的业主才可以进行评价!');
  		return;
  	}
  	if(isPingjia!='0'){
  		alert('您已经评价过该商品，如需要重新评价，请进入"个人管理——评价记录"进行修改!');
  		return;
  	}
  	
	var  type=$("#pgtype").val();
       if("-1"==type)
       {
          alert('请选择评价态度');
          $("#pgtype").focus();
         return;
       }
       var  title=$("#title").val();
       if(""==title){
          alert("请填写标题");
          $("#title").focus();
          return;
       }
       var content =$("#pgcontent").val();
        if(""==content){
          alert("请填写评价内容");
          $("#content").focus();
          return;
       }
       document.getElementById('pjbu').click();
		alert('评价成功');
		hideEvaluate();
		$("#title").val("");
		$("#pgcontent").val("");
		$("#pgtype").val("");
}

function addResult(mes){
	if(mes == '1'){
		 //alert('评价成功');
		$("#title").val("");
		$("#pgcontent").val("");
	}else{
		 alert('评价失败');
	}
	// hideEvaluate();
}
var showann = 0;
function showAnnouncement(){
	var obj = $('#accShow');
	if(showann == 0){
		$("#announcementDiv").show();
		showann = 1;
		obj.html('隐藏');
	}else{
		$("#announcementDiv").hide();
		showann = 0;
		obj.html('显示更多');
	}
}

function reply(id){
	var replyContent = $('#reply_'+id).val();
	if(replyContent == "")
		alert('请填写评论');
	$.get('../pingjia/replyStage.shtml?id='+id+'&content='+encodeURIComponent(replyContent),function(mes){
		if(mes == "1"){
			alert('回复成功');
			window.location.reload();
		}else{
			alert("回复失败");
		}
	})
}

function showReplyArea(id){
	var reply = $("#replyArea_"+id);
	reply.show();
}
function hideReplyArea(id){
	var reply = $("#replyArea_"+id);
	reply.hide();
}
